package com.sgb.zhaocai.view.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sgb.zhaocai.BR;
import com.sgb.zhaocai.R;
import com.sgb.zhaocai.entity.MemberCompanyEntitly;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class MemberPersonalAdapter extends BaseRecycleAdapter<MemberCompanyEntitly> {
    private ImageView ivSelect;
    private RecyclerView recyclerview;

    public MemberPersonalAdapter(Context context, List<MemberCompanyEntitly> datas) {
        super(context, R.layout.member_personal_items, datas);
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
    }

    @Override
    public void convert(ItemViewHolder holder, MemberCompanyEntitly entity) {
        holder.setBinding(BR.viewModel, entity);
        ivSelect = holder.itemView.findViewById(R.id.iv_select);
        recyclerview = holder.itemView.findViewById(R.id.recyclerview);
        ivSelect.setImageResource(entity.isCheck() ? R.drawable.icon_select_item : R.drawable.icon_unselecte);
        ivSelect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                iChildClick.onClick(entity);
            }
        });
        List<String> allCategoryName = entity.getAllCategoryName();
        if (allCategoryName!=null&&allCategoryName.size()>0){
            recyclerview.setVisibility(View.VISIBLE);
            CompanyTabAdapter companytabadapter = new CompanyTabAdapter(context, allCategoryName);
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
            linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
            recyclerview.setLayoutManager(linearLayoutManager);
            recyclerview.setAdapter(companytabadapter);
        }else {
            recyclerview.setVisibility(View.GONE);
        }
    }
    private IChildClick iChildClick;
    public interface IChildClick {
        void onClick(MemberCompanyEntitly membercompanyentitly);
    }

    public void onIChildClick(IChildClick iChildClick) {
        this.iChildClick = iChildClick;
    }
}
